package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 服务器返回出售物品给系统消息
 */
public class Goods_SellToSysReturnProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 16009; }

    public Boolean IsSuccess; //是否成功
    public Integer MsgCode; //消息码

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteBool(IsSuccess);
            if (!IsSuccess) {
            }
            dataStream.WriteInt(MsgCode);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static Goods_SellToSysReturnProto GetProto(byte[] buffer) {
        Goods_SellToSysReturnProto proto = new Goods_SellToSysReturnProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.IsSuccess = dataStream.ReadBool();
            if(!proto.IsSuccess) {
            }
            proto.MsgCode = dataStream.ReadInt();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}